home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Bin / DXUtils / Visual Studio 6.0 Wizards / Source Code / Chooser.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-12  |  11.5 KB  |  446 lines

  1. // chooser.cpp : Implements the CDialogChooser class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <objbase.h>
  6. #include "DxAppWiz.h"
  7. #include "DXaw.h"
  8. #include "chooser.h"
  9. #include "cstm1dlg.h"
  10. #include "cstm2dlg.h"
  11. #include "cstm3dlg.h"
  12. #include "cstm4dlg.h"
  13. #include "cstm5dlg.h"
  14. #include "cstm6dlg.h"
  15. #include "cstm7dlg.h"
  16.  
  17. #ifdef _PSEUDO_DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define DOC_TRACK   0   // MDI/SDI based app track
  23. #define DLG_TRACK   1   // dialog based app track
  24.  
  25. // define the steps, since these are array indices, their values matter
  26. #define STEP_ZERO           0
  27. #define STEP_DX             1
  28. #define STEP_D3D            2
  29. #define STEP_DINPUT         3
  30. #define STEP_DMUSIC         4
  31. #define STEP_DPLAY          5
  32. #define STEP_DSOUND         6
  33.  
  34. // On construction, set up internal array with pointers to each step.
  35. CDialogChooser::CDialogChooser()
  36. {
  37.     m_pDlg1Preview = NULL;
  38.     m_pDlg2Preview = NULL;
  39.     m_pDlg3Preview = NULL;
  40.     m_pDlg4Preview = NULL;
  41.     m_pDlg5Preview = NULL;
  42.  
  43.     m_bWindow      = TRUE;
  44.     m_bMFCDialog   = FALSE;
  45.  
  46.     m_bDirect3D    = TRUE;
  47.     m_bDirectInput = TRUE;
  48.     m_bDirectMusic = TRUE;
  49.     m_bDirectSound = FALSE;
  50.     m_bDirectPlay  = FALSE;
  51.  
  52.     m_bUseMFC      = FALSE;
  53.  
  54.     m_bShowBlank    = FALSE;
  55.     m_bShowTriangle = FALSE;
  56.     m_bShowTeapot   = TRUE;
  57.  
  58.     m_bRegAccess    = TRUE;
  59.     m_bIncludeMenu    = TRUE;
  60.  
  61.     m_pDlgs[STEP_ZERO] = NULL;
  62.  
  63.     m_pDlgs[STEP_DX]     = new CCustom1Dlg( this );
  64.     m_pDlgs[STEP_D3D]    = new CCustom2Dlg( this );
  65.     m_pDlgs[STEP_DINPUT] = new CCustom3Dlg( this );
  66.     m_pDlgs[STEP_DMUSIC] = new CCustom4Dlg;
  67.     m_pDlgs[STEP_DPLAY]  = new CCustom5Dlg( this );
  68.     m_pDlgs[STEP_DSOUND] = new CCustom6Dlg;
  69.  
  70.     m_hBackgroundBitmap = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_BACKGROUND) );
  71.  
  72.     m_hWinBlankPreview     = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_WIN_BLANK) );
  73.     m_hWinTeapotPreview    = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_WIN_TEAPOT) );
  74.     m_hWinTrianglePreview  = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_WIN_TRIANGLE) );
  75.     m_hWinGdiPreview       = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_WIN_GDI) );
  76.  
  77.     m_hDlgBlankPreview     = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_DLG_BLANK) );
  78.     m_hDlgTeapotPreview    = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_DLG_TEAPOT) );
  79.     m_hDlgTrianglePreview  = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_DLG_TRIANGLE) );
  80.     m_hDlgGdiPreview       = ::LoadBitmap( g_hInstance, MAKEINTRESOURCE(IDB_DLG_GDI) );
  81.  
  82.     m_nCurrentPreviewID = IDB_WIN_TEAPOT;
  83.     m_nCurrDlg = 0;
  84. }
  85.  
  86. // Remember where the custom steps begin, so we can delete them in
  87. //  the destructor
  88. #define FIRST_CUSTOM_STEP 1
  89. #define LAST_CUSTOM_STEP 6
  90.  
  91. // The destructor deletes entries in the internal array corresponding to
  92. //  custom steps.
  93. CDialogChooser::~CDialogChooser()
  94. {
  95.     for (int i = FIRST_CUSTOM_STEP; i <= LAST_CUSTOM_STEP; i++)
  96.     {
  97.         ASSERT(m_pDlgs[i] != NULL);
  98.         delete m_pDlgs[i];
  99.     }
  100.  
  101.     DeleteObject( m_hBackgroundBitmap );
  102.     DeleteObject( m_hWinBlankPreview );
  103.     DeleteObject( m_hWinTeapotPreview );
  104.     DeleteObject( m_hWinTrianglePreview );
  105.     DeleteObject( m_hWinGdiPreview );
  106.  
  107.     DeleteObject( m_hDlgBlankPreview );
  108.     DeleteObject( m_hDlgTeapotPreview );
  109.     DeleteObject( m_hDlgTrianglePreview );
  110.     DeleteObject( m_hDlgGdiPreview );
  111. }
  112.  
  113.  
  114. BOOL BIsAlpha(TCHAR c)
  115. {
  116.     if( ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) )
  117.         return TRUE;
  118.     return FALSE;
  119. }
  120.  
  121.  
  122. // Use the internal array to determine the next step.
  123. CAppWizStepDlg* CDialogChooser::Next(CAppWizStepDlg* pDlg)
  124. {
  125.     ASSERT(0 <= m_nCurrDlg && m_nCurrDlg < LAST_DLG);
  126.     ASSERT(pDlg == m_pDlgs[m_nCurrDlg]);
  127.  
  128.     // If the current step is the "project type" step, the AppWizard "track" may
  129.     //  have changed.
  130.     if( m_nCurrDlg == STEP_ZERO )
  131.     {
  132.         TCHAR strBuffer[MAX_PATH];
  133.         ZeroMemory( strBuffer, sizeof(TCHAR)*MAX_PATH );
  134.  
  135.         CString strRoot;
  136.         DirectXaw.m_Dictionary.Lookup( "root", strRoot );
  137.         CString tmp;
  138.         tmp = strRoot.GetAt(0);
  139.         tmp.MakeUpper();
  140.         strRoot.SetAt( 0, tmp[0] );
  141.  
  142.         int i = 0;
  143.         int j = 0;
  144.         while( i < strRoot.GetLength() )
  145.         {
  146.             TCHAR ch = strRoot.GetAt(i);
  147.             if( !BIsAlpha(ch) && ch != '_' )
  148.             {
  149.                 if( i+1 < strRoot.GetLength() )
  150.                 {
  151.                     tmp = strRoot.GetAt(i+1);
  152.                     tmp.MakeUpper();
  153.                     strRoot.SetAt( i+1, tmp[0] );
  154.                 }
  155.             }
  156.             else
  157.             {
  158.                 strBuffer[j++] = ch;
  159.             }
  160.             i++;
  161.         }
  162.         strBuffer[j++] = 0;
  163.         DirectXaw.m_Dictionary["CRoot"] = CString(strBuffer);
  164.  
  165.         GUID guid;
  166.         ZeroMemory( &guid, sizeof(GUID) );
  167.         CoCreateGuid( &guid );
  168.  
  169.         CString strGuidStruct;
  170.         CString strGuidMsg;
  171.         strGuidMsg.Format( TEXT("{%0.8X-%0.4X-%0.4X-%0.2X%0.2X-%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X}"), 
  172.                 guid.Data1, guid.Data2, guid.Data3, 
  173.                 guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
  174.                 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] );
  175.         DirectXaw.m_Dictionary["GUIDMSG"] = strGuidMsg;
  176.  
  177.         strGuidStruct.Format( TEXT("{ 0x%0.8x, 0x%0.4x, 0x%0.4x, { 0x%0.2x, 0x%0.2x, 0x%0.2x, 0x%0.2x, 0x%0.2x, 0x%0.2x, 0x%0.2x, 0x%0.2x } }"), 
  178.                 guid.Data1, guid.Data2, guid.Data3, 
  179.                 guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
  180.                 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] );
  181.         DirectXaw.m_Dictionary["GUIDSTRUCT"] = strGuidStruct;
  182.     }
  183.  
  184.     BOOL bFound = FALSE;
  185.  
  186.     while( !bFound )
  187.     {
  188.         m_nCurrDlg++;
  189.  
  190.         switch( m_nCurrDlg )
  191.         {
  192.         case STEP_DX:
  193.             bFound = TRUE;
  194.             break;
  195.  
  196.         case STEP_D3D:
  197.             if( m_bDirect3D )   
  198.                 bFound = TRUE;
  199.             break;
  200.  
  201.         case STEP_DINPUT:
  202.             if( m_bDirectInput )   
  203.                 bFound = TRUE;
  204.             break;
  205. /*
  206.         case STEP_DMUSIC:
  207.             if( m_bDirectMusic )   
  208.                 bFound = TRUE;
  209.             break;
  210. */
  211.         case STEP_DPLAY:
  212.             if( m_bDirectPlay )   
  213.                 bFound = TRUE;
  214.             break;
  215. /*
  216.         case STEP_DSOUND:
  217.             if( m_bDirectSound )   
  218.                 bFound = TRUE;
  219.             break;
  220. */
  221.         }
  222.     }
  223.  
  224.     if( m_nCurrDlg > LAST_DLG )
  225.         m_nCurrDlg = STEP_DX;
  226.  
  227.     switch( m_nCurrDlg )
  228.     {
  229.         case STEP_DX:
  230.             SetPreviewBitmap( m_pDlg1Preview );
  231.             break;
  232.         case STEP_D3D:
  233.             SetPreviewBitmap( m_pDlg2Preview );
  234.             break;
  235.         case STEP_DINPUT:
  236.             SetPreviewBitmap( m_pDlg3Preview );
  237.             break;
  238.         case STEP_DMUSIC:
  239.             SetPreviewBitmap( m_pDlg4Preview );
  240.             break;
  241.         case STEP_DPLAY:
  242.             SetPreviewBitmap( m_pDlg5Preview );
  243.             break;
  244.         case STEP_DSOUND:
  245.             break;
  246.     }
  247.  
  248.     return m_pDlgs[m_nCurrDlg];
  249. }
  250.  
  251. // Use the internal array to determine the previous step.
  252. CAppWizStepDlg* CDialogChooser::Back(CAppWizStepDlg* pDlg)
  253. {
  254.     ASSERT(1 <= m_nCurrDlg && m_nCurrDlg <= LAST_DLG);
  255.     ASSERT(pDlg == m_pDlgs[m_nCurrDlg]);
  256.  
  257.     BOOL bFound = FALSE;
  258.  
  259.     while( !bFound )
  260.     {
  261.         m_nCurrDlg--;
  262.  
  263.         switch( m_nCurrDlg )
  264.         {
  265.         case STEP_ZERO:
  266.         case STEP_DX:
  267.             bFound = TRUE;
  268.             break;
  269.  
  270.         case STEP_D3D:
  271.             if( m_bDirect3D )   
  272.                 bFound = TRUE;
  273.             break;
  274.  
  275.         case STEP_DINPUT:
  276.             if( m_bDirectInput )   
  277.                 bFound = TRUE;
  278.             break;
  279. /*
  280.         case STEP_DMUSIC:
  281.             if( m_bDirectMusic )   
  282.                 bFound = TRUE;
  283.             break;
  284. */
  285.         case STEP_DPLAY:
  286.             if( m_bDirectPlay )   
  287.                 bFound = TRUE;
  288.             break;
  289. /*
  290.         case STEP_DSOUND:
  291.             if( m_bDirectSound )   
  292.                 bFound = TRUE;
  293.             break;
  294. */
  295.         }
  296.     }
  297.  
  298.     if( m_nCurrDlg < 0 )
  299.         m_nCurrDlg = STEP_DX;
  300.  
  301.     switch( m_nCurrDlg )
  302.     {
  303.         case STEP_DX:
  304.             SetPreviewBitmap( m_pDlg1Preview );
  305.             break;
  306.         case STEP_D3D:
  307.             SetPreviewBitmap( m_pDlg2Preview );
  308.             break;
  309.         case STEP_DINPUT:
  310.             SetPreviewBitmap( m_pDlg3Preview );
  311.             break;
  312.         case STEP_DMUSIC:
  313.             SetPreviewBitmap( m_pDlg4Preview );
  314.             break;
  315.         case STEP_DPLAY:
  316.             SetPreviewBitmap( m_pDlg5Preview );
  317.             break;
  318.         case STEP_DSOUND:
  319.             break;
  320.     }
  321.  
  322.     return m_pDlgs[m_nCurrDlg];
  323. }
  324.  
  325.  
  326. VOID CDialogChooser::InitDialogs()
  327. {
  328.     if( m_bDirect3D )
  329.         m_pDlgs[STEP_D3D]->OnDismiss();
  330.     else
  331.         ((CCustom2Dlg*) m_pDlgs[STEP_D3D])->RemoveAllKeys();
  332.  
  333.     if( m_bDirectInput )
  334.         m_pDlgs[STEP_DINPUT]->OnDismiss();
  335.     else
  336.         ((CCustom3Dlg*) m_pDlgs[STEP_DINPUT])->RemoveAllKeys();
  337.  
  338.     if( m_bDirectPlay )
  339.         m_pDlgs[STEP_DPLAY]->OnDismiss();
  340.     else
  341.         ((CCustom5Dlg*) m_pDlgs[STEP_DPLAY])->RemoveAllKeys();
  342. }
  343.  
  344. void CDialogChooser::UpdatePreviewAndSteps( CStatic* pStatic )
  345. {
  346.     int nPreviewID = IDB_DLG_GDI;
  347.  
  348.     if( m_bDirect3D )
  349.     {
  350.         if( m_bMFCDialog )
  351.         {
  352.             if( m_bShowBlank )
  353.                 nPreviewID = IDB_DLG_BLANK;
  354.             else if( m_bShowTriangle )
  355.                 nPreviewID = IDB_DLG_TRIANGLE;
  356.             else if( m_bShowTeapot )
  357.                 nPreviewID = IDB_DLG_TEAPOT;
  358.         }
  359.         else
  360.         {
  361.             if( m_bShowBlank )
  362.                 nPreviewID = IDB_WIN_BLANK;
  363.             else if( m_bShowTriangle )
  364.                 nPreviewID = IDB_WIN_TRIANGLE;
  365.             else if( m_bShowTeapot )
  366.                 nPreviewID = IDB_WIN_TEAPOT;
  367.         }
  368.     }
  369.     else
  370.     {
  371.         if( m_bMFCDialog )
  372.         {
  373.             nPreviewID = IDB_DLG_GDI;
  374.         }
  375.         else
  376.         {
  377.             nPreviewID = IDB_WIN_GDI;
  378.         }
  379.     }
  380.  
  381.     m_nCurrentPreviewID = nPreviewID;
  382.  
  383.     SetPreviewBitmap( pStatic );
  384.  
  385.     m_nSteps = 1;
  386.  
  387.     if( m_bDirect3D )
  388.         m_nSteps++;
  389.  
  390.     if( m_bDirectInput )
  391.         m_nSteps++;
  392.  
  393.     if( m_bDirectPlay )
  394.         m_nSteps++;
  395.  
  396.     SetNumberOfSteps(m_nSteps);    
  397.  
  398.     if( m_bMFCDialog )
  399.         m_bUseMFC = TRUE;
  400.     else
  401.         m_bUseMFC = FALSE;
  402. }
  403.  
  404.  
  405. VOID CDialogChooser::SetPreviewBitmap( CStatic* pStatic )
  406. {
  407.     if( pStatic == NULL )
  408.         return;
  409.  
  410.     HBITMAP hBitmap = NULL;
  411.     switch( m_nCurrentPreviewID )
  412.     {
  413.         case IDB_WIN_BLANK:
  414.             hBitmap = m_hWinBlankPreview;
  415.             break;
  416.         case IDB_WIN_TEAPOT:
  417.             hBitmap = m_hWinTeapotPreview;
  418.             break;
  419.         case IDB_WIN_TRIANGLE:
  420.             hBitmap = m_hWinTrianglePreview;
  421.             break;
  422.         case IDB_WIN_GDI:
  423.             hBitmap = m_hWinGdiPreview;
  424.             break;
  425.  
  426.         case IDB_DLG_BLANK:
  427.             hBitmap = m_hDlgBlankPreview;
  428.             break;
  429.         case IDB_DLG_TEAPOT:
  430.             hBitmap = m_hDlgTeapotPreview;
  431.             break;
  432.         case IDB_DLG_TRIANGLE:
  433.             hBitmap = m_hDlgTrianglePreview;
  434.             break;
  435.         case IDB_DLG_GDI:
  436.             hBitmap = m_hDlgGdiPreview;
  437.             break;
  438.     }
  439.  
  440.     if( hBitmap && pStatic )
  441.     {
  442.         pStatic->SetBitmap( hBitmap );
  443.         pStatic->InvalidateRect(NULL, FALSE );
  444.     }
  445. }
  446.